<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <%@include file="/WEB-INF/jsp/common.jsp"%>
</head>
<body>
<h2>治疗仪管理</h2>
<hr>
<form action="" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">仪器名称：</label>
            <div class="layui-input-inline">
                <input type="text" id="instrName" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <button type="button" class="layui-btn layui-btn-sm" onclick="reloadData();"><i class="layui-icon layui-icon-search"></i> 搜索</button>
        </div>
    </div>
</form>
<table id="insTable" lay-filter="insTable"></table>
<script>
    function reloadData(){
        layui.table.reload("insTable",{
            page:{
                curr : 1
            },
            where : {
                instrName : $("#instrName").val(),
            }
        })
    }

    layui.use(['table','form','upload','layedit'],function () {
        var table= layui.table;
        var form = layui.form;

        //渲染表格
        table.render({
            elem: '#insTable',
            url: '${path}/ins/list',
            page:true,
            even: true,
            toolbar:'#toolbarDemo',
            cols:[[
                {type:'radio'},
                {field:'instrId',title:'编号',width:80, sort: true},
                {field:'instrName',title:'仪器名称'},
                {field:'instrPic',title:'仪器照片',style:'height:100px;',templet:function (d) {
                        return '<img src=${path}/'+d.instrPic+' style="width:100%;height:100%">'
                    }},
                {field:'instrStatus',title:'仪器状态',templet:function x(d){
                        if (d.instrStatus == 0){
                            return"不可用"
                        }
                        return"可用"
                    }},
                {field:'jiage',title:'价格'},
                {field:'instrText',title:'仪器介绍'},
                {field:'hello', title:'操作',toolbar:'#barDemo'}
            ]]
        })

        table.on("toolbar(insTable)",function (obj) {
            var e = obj.event;

            if (e=="add"){
                $.get('${path}/ins/form',function (str) {
                    layer.open({
                        type: 1,
                        title: '添加治疗仪',
                        area: ['100%','100%'],
                        maxmin: true,
                        content : str,
                        btn:['确定','取消'],
                        success:function(){

                        },
                        yes:function (index) {
                            // alert(layui.layedit.getContent("demo"))
                            layui.layedit.sync(index)
                            var params = $("#instr_info_form").serialize();
                            console.log(params);
                            $.post('${path}/ins/add',params,function () {
                                table.reload('insTable');
                                layer.close(index);
                            })
                        }
                    })
                })
            }
        })
        table.on("tool(insTable)",function (obj) {
            var data = obj.data;
            console.log(data)
            var e = obj.event;
            /*修改仪器信息*/
            if (e == "edit"){
                $.get("${path}/ins/get",{instrID:data.instrId},function (getstr) {
                    $.get('${path}/ins/editform',function (str) {
                        layer.open({
                            type: 1,
                            title: '修改治疗仪',
                            area: ['100%','100%'],
                            maxmin: true,
                            content : str,
                            btn:['确定','取消'],
                            success:function(){
                                form.val('instr_info',getstr);
                            },
                            yes:function (index) {
                                layui.layedit.sync(index)
                                var params = $("#instr_info_form").serialize();
                                console.log(params);
                                $.post('${path}/ins/edit',params,function () {
                                table.reload('insTable');
                                layer.close(index);
                                })
                            }
                        })
                    })
                })
            }else if (e == "del"){
                layer.open({
                    title: "友情提示",
                    content:"你确定删除吗?",
                    btn:['确定','取消'],
                    yes:function () {
                        $.post("${path}/ins/batchDelete",{ids:data.instrId},function () {
                            layer.msg("删除成功了");
                            table.reload('insTable');
                        });
                    }
                })
            }
        })
    })
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <shiro:hasPermission name="zhiliaoyi:add">
            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
        </shiro:hasPermission>
    </div>
</script>
<script type="text/html" id="barDemo">
    <shiro:hasPermission name="zhiliaoyi:upd">
        <a href="javascript:void(0)" lay-event="edit"><i class="layui-icon layui-icon-edit"></i> </a>
    </shiro:hasPermission>
    <shiro:hasPermission name="zhiliaoyi:del">
        <a href="javascript:void(0)" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
    </shiro:hasPermission>
</script>
</body>
</html>
